<template>
    <div class="formSearch">
        <el-form :model="formDataList.searchForm" :label-width="width + 'px'" size="mini">
            <el-form-item :label="item.name" v-for="(item,index) in formDataList.formGroup" :key='item.i_key'>
                <component :is="item.key" :label='item.label' :placeholder='item.placeholder' :comData='item'
                    :classStyle='classStyle'
                    @setFormData='setFormData' ref='component'></component>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import input from './input.vue'
    import inputNumber from './inputNumber.vue'
    import checkInput from './checkInput'
    import datePicker from './checkInput/datePicker.vue'
    import searchInput from './searchInput.vue'
    import formSelect from './formSelect.vue'
    export default {
        data() {
            return {
                searchData:{},
                keyArr:[]
            }
        },
        props: {
            formDataList: {
                type: Object,
                default: () => ({})
            },
            arrayList: {
                type: Array,
                default: () => []
            },
            width:{
                type:Number,
                default:0
            },
            classStyle:{
                type:String,
                default:''
            }
        },
        components: {
            // srk: 普通input输入框; jsk: 计数器; cki: 计划开始/结束时间; dpi: 实际开始/结束时间; sel: 基础多选/单选; sci: 远程搜索
            srk: input,
            jsk: inputNumber,
            cki: checkInput,
            dpi: datePicker,
            sci: searchInput,
            sel: formSelect
        },
        methods: {
            // 获取数据
            getData() {
                // let data = {}
                // this.keyArr = []
                // this.formDataList.formGroup.forEach(i => {
                //     this.keyArr = [...this.keyArr,i.i_key]
                // })
                return this.searchData
            },
            //重置
            reset(){
                this.searchData = {}
                // this.$refs.component.forEach(c =>{
                //     c.reset()
                // })
            },
            setFormData(val) {
                for (let key in val) {
                    // console.log(key)
                    this.searchData[key] = val[key]
                }
            }
        }
    }
</script>